package com.zzyl.reservation.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.Page;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.PageUtils;
import com.zzyl.member.domin.Reservation;
import com.zzyl.member.dto.ReservationDto;
import com.zzyl.member.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;


import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 *
 * @author CHEN
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;


    /**
     * 查询当天取消预约数量
     */
    //@PreAuthorize("@ss.hasPermi('member:reservation:getCancelledCount')")
    @GetMapping("/cancelled-count")
    @ApiOperation(value = "查询当天取消预约数量")
    public AjaxResult getCancelledCount()
    {
        return AjaxResult.success(reservationService.getCancelledCount());
    }

    /**
     * 查询预约信息列表
     */
    //@PreAuthorize("@ss.hasPermi('member:reservation:list')")
    @GetMapping("/page")
    public Map<String, Object> list(Reservation reservation) {
        // 开启分页
        PageUtils.startPage();

        // 查询数据
        List<Reservation> list = reservationService.selectReservationList(reservation);

        // 强转为 Page，获取 total
        Page<Reservation> page = (Page<Reservation>) list;

        // 手动封装成你要的结构
        Map<String, Object> data = new HashMap<>();
        data.put("total", page.getTotal());
        data.put("rows", page.getResult());
        data.put("code", 200);
        data.put("msg", "请求成功");

        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", data);

        return result;
    }


    /**
     * 新增预约
     */
    //@PreAuthorize("@ss.hasPermi('member:reservation:insertReservation')")
    @PostMapping
    @ApiOperation(value = "新增预约")
    public AjaxResult add(@RequestBody ReservationDto reservationDto)
    {
        reservationService.insertReservation(reservationDto);
        return success();
    }


    /**
     * 查询每个时间段剩余预约次数（每个时间段最多六次）
     */
//    @GetMapping("/remaining-count")
//    @ApiOperation(value = "查询每个时间段剩余预约次数")
//    public AjaxResult getRemainingCount(Long time) {
//        return AjaxResult.success(reservationService.getTimingCount(time));
//    }


}
